package com.cloudloan.aop;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudloan.common.R;
import com.cloudloan.entity.CustomPage;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PageAop {

    @Around("@annotation(com.cloudloan.annotion.PageSelect)")
    public Object pageSelect(ProceedingJoinPoint joinPoint) throws Throwable {
        Object proceed = joinPoint.proceed(); //执行原有方法
        if (proceed instanceof R){ //判断是否为同一返回类
            R r = (R) proceed;
            Page data = (Page) r.getData();
           CustomPage newdate = new CustomPage(data.getCurrent(),data.getPages(),data.getTotal(),data.getSize(),data.getRecords());
           return R.success(newdate);
        }
        return proceed;
    }
}
